package com.cnhis.cloudhealth.clinical.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Logger;

import com.cnhis.cloudhealth.commons.utils.PropertiesUtils;
 

/**
 * 工具类
 * @author freeteam
 *
 */
public class PropertiesUtil_prjcli_V2s316 {
	Properties Properties1 = new Properties();
	public PropertiesUtil_prjcli_V2s316(String path) {
		path=path.trim();
		System.out.println( new File(path).exists() +":"+path);
		try {
		FileInputStream	sins = new FileInputStream(path);
		
		Properties1.load(sins);
		} catch (IOException e) {
			ExUtil.throwExV2(e);
		}
	}

	public PropertiesUtil_prjcli_V2s316(InputStream resourceAsStream) {
		try {
		//	、、FileInputStream	sins = InputStream；
			
			Properties1.load(resourceAsStream);
			} catch (IOException e) {
				ExUtil.throwExV2(e);
			}
	}

	public static void main(String[] args) {
		
		//C:\0wkspc\clis413\clinical\target\classes\META-INF\prop\redis.properties
		//C:\0wkspc\clis413\clinical\target\classes\META-INF\prop\redis.properties
		
	//	PropertiesUtil_prjcli_V2s316 cfg=new PropertiesUtil_prjcli_V2s316(PropertiesUtil_prjcli_V2s316.class.getResource("/")+"META-INF/prop/cache.properties");
		PropertiesUtil_prjcli_V2s316 cfg=new PropertiesUtil_prjcli_V2s316(PropertiesUtil_prjcli_V2s316.class.getResourceAsStream("/META-INF/prop/cache.properties"));
		System.out.println(cfg.getConfig("lev1_thrdpool_size"));
//		  String cfgfile=	DoctorordernewRest.class.getResource("/")+"META-INF/prop/log.properties";
//		  System.out.println(cfgfile);
//		    String url=PropertiesUtil.getConfig(cfgfile, "url");
//		System.out.println(url);
	}

	public Object getConfig(String key) {
		// TODO Auto-generated method stub
		return Properties1.getProperty(key);
	}

	//获取配置文件的配置
	public static String getConfig(String path,String name){
		
		if( !new File(path).exists())
			throw new RuntimeException("file nnot 4exist:"+path);
		FileInputStream sins=null;
		String value="";
		try {
			Properties loginprop = new Properties();
			sins = new FileInputStream(path);
			loginprop.load(sins);
			value=loginprop.getProperty(name);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}finally{
			if (sins!=null) {
		        try {
					sins.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return value;
		}
	}

	public static String getConfig_sf(String cfg_reltPath, String key) {
		
		try {
		Thread currentThread = Thread.currentThread();
		@SuppressWarnings("static-access")
	  
			StackTraceElement[] stackTrace = currentThread.getStackTrace();

			StackTraceElement StackTraceElement1_invoker = stackTrace[2];
			// StackTraceElement1_invoker.
		
				Class cls = Class.forName(StackTraceElement1_invoker.getClassName());
				 String cfgfile=	cls.getResource("/").getPath()+cfg_reltPath;
				 return getConfig(cfgfile,key);
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		return "$getConfig_sf_err";
	}

	public Object getConfigWzDefval(String key, String defaultValue) {
		 
		return this.Properties1.getProperty(key, defaultValue);
	}

 

	public int getIntConfigWzDefval(String key, int defaultValue) {
		
	String val=	this.Properties1.getProperty(key, String.valueOf(defaultValue));
	 return Integer.parseInt( val.toString().trim());
	}
	
	public int getConfigIntWzDefval(String key, int defaultValue) {
		
	String val=	this.Properties1.getProperty(key, String.valueOf(defaultValue));
	 return Integer.parseInt( val.toString().trim());
	}
	
	public int getConfigInt(String key ) {
		
	String val=	this.Properties1.getProperty(key);
	 return Integer.parseInt( val.toString().trim());
	}

	public long getConfigLong(String key) {
		String val=	this.Properties1.getProperty(key);
		return  Long.parseLong(val.toString().trim());
	}
}
